﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Gem_Tools.Planning.UserControl;
using Gem_Tools_Entity.Gem_Tools;
using Gem_Tools_Controller.Gem_Tools;
using DevExpress.XtraNavBar;
using Gem_Tools_Utility;
using GE_Management_Tool;
using DevExpress.Skins;
using GE_Management_Tool.Home_Page.UserControl;


namespace Gem_Tools.Planning
{
    public partial class frmA001_Planning_Main : frmBase
    {
        uc1004_To_Do_List m_uc01 = new uc1004_To_Do_List();
        uc1004_To_Do_List_Manager m_uc02 = new uc1004_To_Do_List_Manager();
        IList<CProject> m_lsProject;
        ucA001_Project_Schedule m_uc;

        public frmA001_Planning_Main()
        {
            InitializeComponent();
            CCommon_Function.Format_All(this);
            if ((CSession.Active_Staff.Regency_ID != CUtility.Convert_To_Int32(EStaff_Type.Producer)) && (CSession.Active_Staff.Regency_ID != CUtility.Convert_To_Int32(EStaff_Type.Admin)))
            {
                navGroupProject.Visible = false;
            }
        }

        private void Load_Skin()
        {
            foreach (SkinContainer cnt in SkinManager.Default.Skins)
                cbbSkin.Properties.Items.Add(cnt.SkinName);
        }

        private void Load_UC(XtraUserControl p_uc)
        {
            PanelMain.Controls.Clear();
            PanelMain.Controls.Add(p_uc);
            p_uc.Dock = DockStyle.Fill;
        }

        private void frmA001_Planning_Main_Load(object sender, EventArgs e)
        {
            try
            {
                lbUser.Text = "User: " + CSession.Active_Staff.Full_Name;
                lbUser_Time.Text = "Login Time: " + DateTime.Now.ToString("dd-MMM-yyyy HH:mm");
                Load_Skin();
                m_lsProject = new List<CProject>();
                CProject_Controller v_objCtrlProject = new CProject_Controller();
                m_lsProject = v_objCtrlProject.List_Project();

                //cập nhật toàn bộ danh sách lên navbar:

                foreach(CProject v_obj in m_lsProject)
                {
                    NavBarItem v_Item = new NavBarItem(v_obj.Name);
                    v_Item.SmallImageIndex = 3;
                    v_Item.LinkClicked += v_Item_LinkClicked;
                    v_Item.Tag = v_obj;
                    navGroupProject.ItemLinks.Add(v_Item);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        void v_Item_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            try
            {
                //chuyển màu tất cả đối tượng khác sang transparent.
                foreach (NavBarItemLink item in navGroupProject.ItemLinks)
                {
                    item.Item.Enabled = true;
                }

                //đổi màu đối tượng được chọn.
                NavBarItem v_Item = (NavBarItem)sender;
                v_Item.Enabled = false;
                frmLoading v_frm = new frmLoading();
                v_frm.Show();
                v_frm.Update();
                System.Threading.Thread.Sleep(700);
                CProject v_Selected_Project = (CProject)((NavBarItem)sender).Tag;
                CConfig.g_intGem_Tools_Current_Project = v_Selected_Project.Auto_ID;
                m_uc = new ucA001_Project_Schedule();
                m_uc.Dock = DockStyle.Fill;
                PanelMain.Controls.Clear();
                PanelMain.Controls.Add(m_uc);
                if (m_uc01 != null)
                {
                    m_uc01.Dispose();
                }
                if (m_uc02 != null)
                {
                    m_uc02.Close();
                }
                v_frm.Exit_Loading();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnCreateNewProject_Click(object sender, EventArgs e)
        {
            try
            {
                frmA0011_Project_Edit_Page v_frm = new frmA0011_Project_Edit_Page();
                CProject v_project = v_frm.Show_To_Create();
                if (v_project != null)
                {
                    NavBarItem v_Item = new NavBarItem(v_project.Name);
                    v_Item.SmallImageIndex = 3;
                    v_Item.LinkClicked += v_Item_LinkClicked;
                    v_Item.Tag = v_project;
                    navGroupProject.ItemLinks.Add(v_Item);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void frmA001_Planning_Main_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.A && e.Control)
                {
                    m_uc.Proccess_Key_Down(false);
                }

                if (e.KeyCode == Keys.B && e.Control)
                {
                    m_uc.Proccess_Key_Down(true);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void cbbSkin_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.LookAndFeel.SetSkinStyle(cbbSkin.Text);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnToDoList_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            try
            {
                if (CSession.Active_Staff.Regency_ID == CUtility.Convert_To_Int32(EStaff_Type.Artist))
                {
                    m_uc01.Dock = DockStyle.Fill;
                    PanelMain.Controls.Clear();
                    PanelMain.Controls.Add(m_uc01);
                }
                else
                {
                    m_uc02.Dock = DockStyle.Fill;
                    PanelMain.Controls.Clear();
                    PanelMain.Controls.Add(m_uc02);
                    m_uc02.Start();
                }
                
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnDocument_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            try
            {
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnHistory_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            try
            {
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

    }
}